/**
 * Created by Administrator on 2017/9/5.
 * 跳转路由
 * 集成了weex的navigator模块
 */
import loginFilter from 'filters/loginFilter';
const navigator = weex.requireModule('navigator');

function push(options){
    options = options || {};
    options.animated = true;
    let _url = options.url;

    //验证路由跳转用户登录机制 路由配置为object
    if(_url && Object.prototype.toString.call(_url) == '[object Object]') {
        options.url = _url.url;
        if(_url.author && _url.author === true) { //需要验证用户登录
            loginFilter.isLogin(_url.author).then(user => {
                console.log("登录成功");
                navigator.push(options);
            }, () =>{
                console.log('登录异常');
            });
        } else {
            navigator.push(options);
        }
    } else {
        navigator.push(options);
    }
}

function pop(isPop){
    let options = {};
    if(isPop) options.isPop = isPop;
    _pop(options);
}

function _pop(options){
    options = options || {};
    options.animated = false;
    navigator.pop(options);
}


exports.push = push;
exports.pop = pop;